using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodePlex.SpaceBlock;
using System.Threading;
using System.Diagnostics;
using CodePlex.Resourceful;

namespace CodePlex.SpaceBlock.UI.Controls
{
    public partial class BaseControl : UserControl, ISupportDialogKeys
    {

        public event EventHandler<DialogKeyEventArgs> ProcessingDialogKey;

        public BaseControl()
        {
            InitializeComponent();

            this.KeyPress += delegate(object sender, KeyPressEventArgs e)
            {
                object o = e;
            };
        }

        [DebuggerHidden]
        public void InDisplay(Operation action)
        {
            if (this.IsHandleCreated)
            {
                this.Invoke(action);
            }
            else
            {
                this.HandleCreated += delegate
                {
                    this.Invoke(action);
                };
            }
        }

        [DebuggerHidden]
        public void InBackground(Operation action)
        {
             this.InBackground(action, null);
        }

        [DebuggerHidden]
        public void InBackground(Operation action, Operation callback)
        {
            Operation doit = delegate
            {
                action();
                if (callback != null)
                {
                    callback();
                }
            };

            doit.BeginInvoke(null, null);
        }



  

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (ProcessingDialogKey != null)
            {
                DialogKeyEventArgs args = new DialogKeyEventArgs(keyData);

                ProcessingDialogKey(this, args);
            }
            return base.ProcessDialogKey(keyData);
        }


        protected void HandleException(Exception ex)
        {
            UIManager.Instance.ExceptionForm.Show(ex);
        }



        protected string Inputbox(
            Icon icon,
            string title,
            string description,
            string prompt,
            bool hideText,
            Control customControl)
        {
            Form form = this.FindForm() as Form;
            return UIUtils.Inputbox(form, icon, title, description, prompt, hideText, customControl);
        }


        protected  bool YesNo(
            Icon icon,
            string title,
            string description)
        {
            Form form = this.FindForm() as Form;
            return UIUtils.YesNo(form, icon, title, description);
        }
    }
}
